package com.ztgf.shopping.api.cms.shop;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.StrUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import com.ztgf.shopping.models.service.shop.IShopEarnestMoneyLogService;
import com.ztgf.shopping.models.bo.shop.ShopEarnestMoneyLogSaveBO;
import com.ztgf.shopping.models.bo.shop.ShopEarnestMoneyLogBO;
import com.ztgf.shopping.models.dto.shop.ShopEarnestMoneyLogDTO;

/**
 * 店铺保证金日志表控制器
 *
 * @author zhanghualang
 * @Date 2020-05-27 14:43:37
 */

@RestController
@RequestMapping("/cms/shopEarnestMoneyLog")
@Slf4j
@Api(value = "ShopEarnestMoneyLogController",tags = "店铺保证金日志表接口")
public class ShopEarnestMoneyLogController {

    @DubboReference
    private IShopEarnestMoneyLogService shopEarnestMoneyLogService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<ShopEarnestMoneyLogDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        ShopEarnestMoneyLogDTO dto = shopEarnestMoneyLogService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "店铺保证金日志表列表",notes = "店铺保证金日志表列表")
    @PostMapping("/queryPageList")
    public Result<Page<ShopEarnestMoneyLogDTO>> queryPageList( ShopEarnestMoneyLogBO bo){
        Wrapper<ShopEarnestMoneyLogDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("type", 1);//类型 0缴纳、1扣除、2退回

        if (bo.getShopId() != null){
            wrapper.eq("shop_id", bo.getShopId());
        }

        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());
        }
        wrapper.orderBy("create_time", false);//降序

        Page<ShopEarnestMoneyLogDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = shopEarnestMoneyLogService.selectPage(page, wrapper);

        return new Result<>(page);
    }

    @ApiOperation(value = "店铺保证金退还列表",notes = "店铺保证金退还列表")
    @PostMapping("/queryReturnList")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<List<ShopEarnestMoneyLogDTO>> queryReturnList(@RequestParam("id") Long id){
        Wrapper<ShopEarnestMoneyLogDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("type", 2);//类型 0缴纳、1扣除、2退回
        wrapper.eq("shop_id", id);
        wrapper.orderBy("create_time", false);//降序
        return new Result<>(shopEarnestMoneyLogService.selectList(wrapper));
    }
}
